// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using System;
using System.Linq;
using Elastic.Clients.Elasticsearch.Serialization;

namespace Elastic.Clients.Elasticsearch.IndexManagement.Json;

public sealed partial class GetSampleStatsResponseConverter : System.Text.Json.Serialization.JsonConverter<Elastic.Clients.Elasticsearch.IndexManagement.GetSampleStatsResponse>
{
	private static readonly System.Text.Json.JsonEncodedText PropLastException = System.Text.Json.JsonEncodedText.Encode("last_exception");
	private static readonly System.Text.Json.JsonEncodedText PropPotentialSamples = System.Text.Json.JsonEncodedText.Encode("potential_samples");
	private static readonly System.Text.Json.JsonEncodedText PropSamplesAccepted = System.Text.Json.JsonEncodedText.Encode("samples_accepted");
	private static readonly System.Text.Json.JsonEncodedText PropSamplesRejectedForCondition = System.Text.Json.JsonEncodedText.Encode("samples_rejected_for_condition");
	private static readonly System.Text.Json.JsonEncodedText PropSamplesRejectedForException = System.Text.Json.JsonEncodedText.Encode("samples_rejected_for_exception");
	private static readonly System.Text.Json.JsonEncodedText PropSamplesRejectedForMaxSamplesExceeded = System.Text.Json.JsonEncodedText.Encode("samples_rejected_for_max_samples_exceeded");
	private static readonly System.Text.Json.JsonEncodedText PropSamplesRejectedForRate = System.Text.Json.JsonEncodedText.Encode("samples_rejected_for_rate");
	private static readonly System.Text.Json.JsonEncodedText PropSamplesRejectedForSize = System.Text.Json.JsonEncodedText.Encode("samples_rejected_for_size");
	private static readonly System.Text.Json.JsonEncodedText PropTimeCompilingCondition = System.Text.Json.JsonEncodedText.Encode("time_compiling_condition");
	private static readonly System.Text.Json.JsonEncodedText PropTimeCompilingConditionMillis = System.Text.Json.JsonEncodedText.Encode("time_compiling_condition_millis");
	private static readonly System.Text.Json.JsonEncodedText PropTimeEvaluatingCondition = System.Text.Json.JsonEncodedText.Encode("time_evaluating_condition");
	private static readonly System.Text.Json.JsonEncodedText PropTimeEvaluatingConditionMillis = System.Text.Json.JsonEncodedText.Encode("time_evaluating_condition_millis");
	private static readonly System.Text.Json.JsonEncodedText PropTimeSampling = System.Text.Json.JsonEncodedText.Encode("time_sampling");
	private static readonly System.Text.Json.JsonEncodedText PropTimeSamplingMillis = System.Text.Json.JsonEncodedText.Encode("time_sampling_millis");

	public override Elastic.Clients.Elasticsearch.IndexManagement.GetSampleStatsResponse Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
	{
		reader.ValidateToken(System.Text.Json.JsonTokenType.StartObject);
		LocalJsonValue<string?> propLastException = default;
		LocalJsonValue<long> propPotentialSamples = default;
		LocalJsonValue<long> propSamplesAccepted = default;
		LocalJsonValue<long> propSamplesRejectedForCondition = default;
		LocalJsonValue<long> propSamplesRejectedForException = default;
		LocalJsonValue<long> propSamplesRejectedForMaxSamplesExceeded = default;
		LocalJsonValue<long> propSamplesRejectedForRate = default;
		LocalJsonValue<long> propSamplesRejectedForSize = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.Duration?> propTimeCompilingCondition = default;
		LocalJsonValue<System.TimeSpan> propTimeCompilingConditionMillis = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.Duration?> propTimeEvaluatingCondition = default;
		LocalJsonValue<System.TimeSpan> propTimeEvaluatingConditionMillis = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.Duration?> propTimeSampling = default;
		LocalJsonValue<System.TimeSpan> propTimeSamplingMillis = default;
		while (reader.Read() && reader.TokenType is System.Text.Json.JsonTokenType.PropertyName)
		{
			if (propLastException.TryReadProperty(ref reader, options, PropLastException, null))
			{
				continue;
			}

			if (propPotentialSamples.TryReadProperty(ref reader, options, PropPotentialSamples, null))
			{
				continue;
			}

			if (propSamplesAccepted.TryReadProperty(ref reader, options, PropSamplesAccepted, null))
			{
				continue;
			}

			if (propSamplesRejectedForCondition.TryReadProperty(ref reader, options, PropSamplesRejectedForCondition, null))
			{
				continue;
			}

			if (propSamplesRejectedForException.TryReadProperty(ref reader, options, PropSamplesRejectedForException, null))
			{
				continue;
			}

			if (propSamplesRejectedForMaxSamplesExceeded.TryReadProperty(ref reader, options, PropSamplesRejectedForMaxSamplesExceeded, null))
			{
				continue;
			}

			if (propSamplesRejectedForRate.TryReadProperty(ref reader, options, PropSamplesRejectedForRate, null))
			{
				continue;
			}

			if (propSamplesRejectedForSize.TryReadProperty(ref reader, options, PropSamplesRejectedForSize, null))
			{
				continue;
			}

			if (propTimeCompilingCondition.TryReadProperty(ref reader, options, PropTimeCompilingCondition, null))
			{
				continue;
			}

			if (propTimeCompilingConditionMillis.TryReadProperty(ref reader, options, PropTimeCompilingConditionMillis, static System.TimeSpan (ref System.Text.Json.Utf8JsonReader r, System.Text.Json.JsonSerializerOptions o) => r.ReadValueEx<System.TimeSpan>(o, typeof(Elastic.Clients.Elasticsearch.Serialization.TimeSpanMillisMarker))))
			{
				continue;
			}

			if (propTimeEvaluatingCondition.TryReadProperty(ref reader, options, PropTimeEvaluatingCondition, null))
			{
				continue;
			}

			if (propTimeEvaluatingConditionMillis.TryReadProperty(ref reader, options, PropTimeEvaluatingConditionMillis, static System.TimeSpan (ref System.Text.Json.Utf8JsonReader r, System.Text.Json.JsonSerializerOptions o) => r.ReadValueEx<System.TimeSpan>(o, typeof(Elastic.Clients.Elasticsearch.Serialization.TimeSpanMillisMarker))))
			{
				continue;
			}

			if (propTimeSampling.TryReadProperty(ref reader, options, PropTimeSampling, null))
			{
				continue;
			}

			if (propTimeSamplingMillis.TryReadProperty(ref reader, options, PropTimeSamplingMillis, static System.TimeSpan (ref System.Text.Json.Utf8JsonReader r, System.Text.Json.JsonSerializerOptions o) => r.ReadValueEx<System.TimeSpan>(o, typeof(Elastic.Clients.Elasticsearch.Serialization.TimeSpanMillisMarker))))
			{
				continue;
			}

			if (options.UnmappedMemberHandling is System.Text.Json.Serialization.JsonUnmappedMemberHandling.Skip)
			{
				reader.SafeSkip();
				continue;
			}

			throw new System.Text.Json.JsonException($"Unknown JSON property '{reader.GetString()}' for type '{typeToConvert.Name}'.");
		}

		reader.ValidateToken(System.Text.Json.JsonTokenType.EndObject);
		return new Elastic.Clients.Elasticsearch.IndexManagement.GetSampleStatsResponse(Elastic.Clients.Elasticsearch.Serialization.JsonConstructorSentinel.Instance)
		{
			LastException = propLastException.Value,
			PotentialSamples = propPotentialSamples.Value,
			SamplesAccepted = propSamplesAccepted.Value,
			SamplesRejectedForCondition = propSamplesRejectedForCondition.Value,
			SamplesRejectedForException = propSamplesRejectedForException.Value,
			SamplesRejectedForMaxSamplesExceeded = propSamplesRejectedForMaxSamplesExceeded.Value,
			SamplesRejectedForRate = propSamplesRejectedForRate.Value,
			SamplesRejectedForSize = propSamplesRejectedForSize.Value,
			TimeCompilingCondition = propTimeCompilingCondition.Value,
			TimeCompilingConditionMillis = propTimeCompilingConditionMillis.Value,
			TimeEvaluatingCondition = propTimeEvaluatingCondition.Value,
			TimeEvaluatingConditionMillis = propTimeEvaluatingConditionMillis.Value,
			TimeSampling = propTimeSampling.Value,
			TimeSamplingMillis = propTimeSamplingMillis.Value
		};
	}

	public override void Write(System.Text.Json.Utf8JsonWriter writer, Elastic.Clients.Elasticsearch.IndexManagement.GetSampleStatsResponse value, System.Text.Json.JsonSerializerOptions options)
	{
		writer.WriteStartObject();
		writer.WriteProperty(options, PropLastException, value.LastException, null, null);
		writer.WriteProperty(options, PropPotentialSamples, value.PotentialSamples, null, null);
		writer.WriteProperty(options, PropSamplesAccepted, value.SamplesAccepted, null, null);
		writer.WriteProperty(options, PropSamplesRejectedForCondition, value.SamplesRejectedForCondition, null, null);
		writer.WriteProperty(options, PropSamplesRejectedForException, value.SamplesRejectedForException, null, null);
		writer.WriteProperty(options, PropSamplesRejectedForMaxSamplesExceeded, value.SamplesRejectedForMaxSamplesExceeded, null, null);
		writer.WriteProperty(options, PropSamplesRejectedForRate, value.SamplesRejectedForRate, null, null);
		writer.WriteProperty(options, PropSamplesRejectedForSize, value.SamplesRejectedForSize, null, null);
		writer.WriteProperty(options, PropTimeCompilingCondition, value.TimeCompilingCondition, null, null);
		writer.WriteProperty(options, PropTimeCompilingConditionMillis, value.TimeCompilingConditionMillis, null, static (System.Text.Json.Utf8JsonWriter w, System.Text.Json.JsonSerializerOptions o, System.TimeSpan v) => w.WriteValueEx<System.TimeSpan>(o, v, typeof(Elastic.Clients.Elasticsearch.Serialization.TimeSpanMillisMarker)));
		writer.WriteProperty(options, PropTimeEvaluatingCondition, value.TimeEvaluatingCondition, null, null);
		writer.WriteProperty(options, PropTimeEvaluatingConditionMillis, value.TimeEvaluatingConditionMillis, null, static (System.Text.Json.Utf8JsonWriter w, System.Text.Json.JsonSerializerOptions o, System.TimeSpan v) => w.WriteValueEx<System.TimeSpan>(o, v, typeof(Elastic.Clients.Elasticsearch.Serialization.TimeSpanMillisMarker)));
		writer.WriteProperty(options, PropTimeSampling, value.TimeSampling, null, null);
		writer.WriteProperty(options, PropTimeSamplingMillis, value.TimeSamplingMillis, null, static (System.Text.Json.Utf8JsonWriter w, System.Text.Json.JsonSerializerOptions o, System.TimeSpan v) => w.WriteValueEx<System.TimeSpan>(o, v, typeof(Elastic.Clients.Elasticsearch.Serialization.TimeSpanMillisMarker)));
		writer.WriteEndObject();
	}
}